package GUI;

import javax.swing.*;
import layout.TableLayout;

/**
 *
 * @author Tim
 */
public class ServerClient {
    
    /**
     *
     */
    public Controller gc;
    /**
     *
     */
    public Controllers.ServerClient sc;
    /**
     *
     */
    public JButton ok;
    /**
     *
     */
    /**
     *
     */
    public JRadioButton server, client;
    /**
     *
     */
    /**
     *
     */
    public JTextField ipText, speelText;
    
    double b = 10; // Border
    double f = TableLayout.FILL; // Fill
    double p = TableLayout.PREFERRED; //Preferred
    double vs = 5;// Vertical space between labels and text fields
    double vg = 10; // Vertical gap between form elements
    double hg = 10; // Horizontal gap between form elements

    /**
     *
     * @param gc
     */
    public ServerClient(Controller gc) {
        this.gc = gc;
        sc = new Controllers.ServerClient(this);
    }

    /**
     *
     */
    public void createGUI() {
        gc.changeTitle("Server/Client");
        
        double size[][] = {
           //0, 1, 2, 3, 4, 5, 6, 7, 8
            {b, p, b, p, b, p, f}, // Cols
            {b, p, b, p, b, p, b, p, b, p, b, p, f} // Rows
        };

        gc.setLayout(new TableLayout(size));

        server = new JRadioButton();
        server.setText("Nieuw spel starten");
        client = new JRadioButton();
        client.setText("Meedoen aan een bestaand spel");
        client.setSelected(true);

        ButtonGroup radioGroup = new ButtonGroup();
        radioGroup.add(server);
        radioGroup.add(client);

        JLabel ipLabel = new JLabel("IP");
        ipText = new JTextField(15);

        JLabel saldoLabel = new JLabel("Uw saldo is: \u20ac" + gc.spelerIngelogd.getSaldo());
        JLabel speelLabel = new JLabel("Speel bedrag");
        speelText = new JTextField(15);
        speelText.setText(""+gc.spelerIngelogd.getSaldo());

        JPanel buttonPanel = new JPanel();
        ok = new JButton("Ok");
        ok.addActionListener(sc);
        buttonPanel.add(ok);
                      //c, r, c, r   ===> c = Cols; r = Rows;
        gc.add(server, "1, 1, 1, 1");
        gc.add(client, "1, 3, 1, 3");
        gc.add(ipLabel, "3, 3, 3, 3");
        gc.add(ipText, "5, 3, 5, 3");
        gc.add(saldoLabel, "3, 7, 5, 7");
        gc.add(speelLabel, "3, 9, 3, 9");
        gc.add(speelText, "5, 9, 5, 9");
        gc.add(buttonPanel, "1, 11, 5, 11");

    }
}
